package com.view.cn.mvprxjava.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Zengxiaoping on 2016/11/28.
 */
public class MyView extends View {

	//1.创建一个画笔
	private Paint mPaint = new Paint();
	//2.初始化画笔

	//


	public MyView(Context context) {
		super(context);
	}

	public MyView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initPaint();
	}

	private void initPaint() {
		/**
		 * STROKE                //描边
		 * FILL                  //填充
		 * FILL_AND_STROKE       //描边加填充
		 */
		mPaint.setStyle(Paint.Style.FILL);  //设置画笔模式为填充
		mPaint.setColor(Color.BLACK);       //设置画笔颜色
		mPaint.setStrokeWidth(10f);         //设置画笔宽度为10px
	}


	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		initCanvas(canvas);

		//画点
		canvas.drawPoint(200, 200, mPaint);
		canvas.drawPoints(new float[]{500, 400, 500, 500, 500, 600}, mPaint);
		//画线
		canvas.drawLine(300, 300, 500, 600, mPaint);
		//画矩形
		canvas.drawRect(50, 50, 100, 100, mPaint);
		//画圆角矩形
		RectF rectF = new RectF(100, 100, 150, 150);
		canvas.drawRoundRect(rectF, 10, 10, mPaint);
		//画椭圆
		RectF rectF1 = new RectF(150, 150, 400, 200);
		canvas.drawOval(rectF1, mPaint);
		//画圆
		canvas.drawCircle(400, 400, 50, mPaint);
	}

	//初始化画板
	private void initCanvas(Canvas canvas) {
		canvas.drawColor(Color.BLUE);
	}
}
